package com.haipumi.redis;

import java.util.List;
import java.util.Map;
import java.util.Set;

import org.springframework.data.redis.core.RedisTemplate;

public class SpringRedisClientImpl implements SpringRedisClient {
	
	private RedisTemplate redisTemple;
	
	public void setRedisTemple(RedisTemplate redisTemple) {
		this.redisTemple = redisTemple;
	}
	
	@Override
	public void setMap(Object key, Map map) {
		this.redisTemple.opsForHash().putAll(key, map);
	}
	
	@Override
	public Map getMap(Object key) {
		return this.redisTemple.opsForHash().entries(key);
	}

	@Override
	public void setKey(String key, Object value) {
		this.redisTemple.opsForValue().set(key, value);
	}

	@Override
	public Object getKey(String key) {
		return this.redisTemple.opsForValue().get(key);
	}

	@Override
	public void incr(String key) {
		this.redisTemple.opsForValue().increment(key, 1);
	}

	@Override
	public void lPush(String key, String value) {
		this.redisTemple.opsForList().leftPush(key, value);
	}
	
	@Override
	public void RPush(String key, String value) {
		this.redisTemple.opsForList().rightPush(key, value);
	}

	@Override
	public boolean checkKey(String key) {
		return this.redisTemple.hasKey(key);
	}

	@Override
	public Object lIndel(String key) {
		return this.redisTemple.opsForList().index(key, 0);
	}

	@Override
	public Long lLength(String key) {
		return this.redisTemple.opsForList().size(key);
	}

	@Override
	public String lPop(String key) {
		return (String) this.redisTemple.opsForList().leftPop(key);
	}

	@Override
	public Set<String> getKeys(String pattern) {
		return this.redisTemple.keys(pattern);
	}

	@Override
	public List<String> getList(String key,long start,long end) {
		return this.redisTemple.opsForList().range(key, start, end);
	}

}
